package com.okoj.excel_lib_rary.adapter;

import com.blankj.utilcode.util.ConvertUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.okoj.excel_lib_rary.R;
import com.okoj.excel_lib_rary.data.entity.RemoteFile;
import com.okoj.excel_lib_rary.util.FileUtil;

public class RemoteFileAdapter extends BaseQuickAdapter<RemoteFile, BaseViewHolder> {

    public RemoteFileAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, RemoteFile item) {
        String time = item.getModify_time();
        helper.setText(R.id.tv_name,item.getName());
        helper.setText(R.id.tv_time,time);
        helper.setText(R.id.tv_size, ConvertUtils.byte2FitMemorySize(item.getSize(),1));
        helper.setImageResource(R.id.iv_icon,getIcon(item.getDownload_url()));
    }

    private int getIcon(String fileName){
        String serverArgumentFileType = "";
        try {
            serverArgumentFileType = FileUtil.getServerArgumentFileType(fileName);
        } catch (Exception e) {
            e.printStackTrace();
        }

        if(serverArgumentFileType.equals("s")){
            return R.mipmap.aa_icon_xls;
        }else if (serverArgumentFileType.equals("w")){
            return R.mipmap.aa_icon_doc;
        }else if(serverArgumentFileType.equals("p")){
            return R.mipmap.aa_icon_ppt;
        }else {
            return R.mipmap.aa_icon_ppt;
        }

    }
}
